314c2e66d3933e03132c7751e0ef97a34d652021,src/edu/stanford/nlp/util/concurrent/ConcurrentHashIndex.java,ConcurrentHashIndex,indexOf,#E#boolean#,70
Before Change
@Override
public int indexOf(E o, boolean add) {
Integer atomic = item2Index.get(o);
if (atomic == null) {
if (add) {
final int newIndex = indexCounter.getAndIncrement();
atomic = item2Index.putIfAbsent(o, newIndex);
if (atomic == null) {
index2Item.put(newIndex, o);
return newIndex;
} else {
return item2Index.get(o);
}
} else {
return UNKNOWN_ID;
}
} else {
return atomic;
}
}
After Change
}
@Override
public int indexOf(E o, boolean add) {
if (add) {
// TODO(spenceg) The Index interface contract states that indices must be
// non-negative and continuous. We tried to satisfy this requirement without
// a lock (e.g., by using AtomicInteger) but couldn't make it work.
synchronized(this) {
if ( ! item2Index.containsKey(o)) {
item2Index.put(o, indexCounter++);
index2Item.add(o);
assert index2Item.size() == indexCounter;
}
}
return item2Index.get(o);
} else {
return indexOf(o);
}
}